const db = wx.cloud.database() //拿到数据库的引用
const shops = db.collection("shops") //拿到集合的引用
Page({
  data: {
    value: '',
    hotShops: '',
    shopList: '',
  },
  onLoad() {

  },
  onShareAppMessage() {},

  onShareTimeline() {},

  search() {
    const that = this
    shops.where({
      shop_name: db.RegExp({
        regexp: '.*' + that.data.value,
        options: 'i',
      })
    }).orderBy('create_time', 'desc').limit(10).get({
      success: function (res) {
        that.setData({
          shopList: res.data
        })
      }
    })
  },

  seeOne(event) {
    console.log(event.target.dataset.shop)

    wx.navigateTo({
      url: '/pages/luck/index?shop_id=' + event.target.dataset.shop
    })
  },
  onLoad: function () {

    const that = this

    shops.orderBy('create_time', 'desc').limit(3).get({
      success: function (res) {
        that.setData({
          hotShops: res.data
        })
      }
    })

    shops.orderBy('create_time', 'desc').limit(10).get({
      success: function (res) {
        that.setData({
          shopList: res.data
        })
      }
    })



  },
});